package graphics.objects;
import graphics.system.Color;
import graphics.system.Texture;
import graphics.system.TextureContainer;
import tools.Point;
public abstract class GShape extends GraphicsObject {
	/**
	 * scales the shadow (default = no scale), value = absolute pixels to be scaled
	 */
	protected float glowscale;
	protected boolean hasGlow;
	protected boolean hasShadow;
	protected boolean hasTexture;
	protected boolean globalCoords;
	protected float globalCoordScale;
	protected Texture texture;
	protected Texture normalTexture;
	protected boolean hasNormalmap;
	public GShape(Point pos, float angle, Color color) {
		super(pos, angle, color);
		glowscale = 10;
		hasGlow = false;
		hasShadow = true;
		isshape = true;
		globalCoordScale = 0.01f;
	}
	public float getShadowScale() {
		return glowscale;
	}
	public void setGlowScale(float glowscale) {
		this.glowscale = glowscale;
	}
	public void setGlow(boolean glow) {
		this.hasGlow = glow;
	}
	public String toFileString() {
		String s = super.toFileString();
		s = s + "/" + hasGlow + "/" + hasShadow;
		if (hasTexture) {
			s = s + "/" + texture.name;
		}
		else {
			s = s + "/none";
		}
		if (hasNormalmap) {
			s = s + "/" + this.normalTexture.name;
		}
		else {
			s = s + "/none";
		}
		s = s + "/" + this.globalCoords + "/" + this.globalCoordScale;
		return s;
	}
	public int fromFileString(String s) {
		int off = super.fromFileString(s);
		String l[] = s.split("/");
		this.hasGlow = Boolean.valueOf(l[off + 1]);
		this.hasShadow = Boolean.valueOf(l[off + 2]);
		if (!l[off + 3].contains("none")) {
			this.setTexture(TextureContainer.getTexture(l[off + 3]));
		}
		else {
			hasTexture = false;
		}
		if (!l[off + 4].contains("none")) {
			this.setNormalTexture(TextureContainer.getTexture(l[off + 4]));
		}
		else {
			hasNormalmap = false;
		}
		this.globalCoords = Boolean.valueOf(l[off + 5]);
		this.globalCoordScale = Float.valueOf(l[off + 6]);
		return off + 6;
	}
	public boolean hasGlow() {
		return hasGlow;
	}
	public boolean hasShadow() {
		return hasShadow;
	}
	public void setShadow(boolean value) {
		hasShadow = value;
	}
	public void setTexture(Texture t) {
		if (t != null) {
			this.texture = t;
			this.hasTexture = true;
		}
		else {
			hasTexture = false;
		}
	}
	public boolean hasGlobalCoords() {
		return globalCoords;
	}
	public void setGlobalCoords(boolean gc) {
		this.globalCoords = gc;
	}
	public float getGlobalCoordScale() {
		return globalCoordScale;
	}
	public void setGlobalCoordScale(float globalCoordScale) {
		this.globalCoordScale = globalCoordScale;
	}
	public void setNormalTexture(Texture t) {
		if (t == null) {
			hasNormalmap = false;
			return;
		}
		this.normalTexture = t;
		this.hasNormalmap = true;
	}
	public boolean hasNormalMap() {
		return hasNormalmap;
	}
	public String getNormalName() {
		return normalTexture.name;
	}
	public boolean hasTexture() {
		return hasTexture;
	}
	public void setHasTexture(boolean hasTexture) {
		this.hasTexture = hasTexture;
	}
	public String getTextureName() {
		return this.texture.name;
	}
}
